package com.mes_for_xxxxxx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mes_for_xxxxxx.entity.Employee;
import com.mes_for_xxxxxx.entity.dto.LoginDTO;
import com.mes_for_xxxxxx.mapper.EmployeeMapper;
import com.mes_for_xxxxxx.service.IEmployeeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mes_for_xxxxxx.utils.JwtUtil;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Objects;

/**
 * <p>
 * 员工信息表 服务实现类
 * </p>
 *
 * @author 179005
 * @since 2024-09-10
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {

    @Override
    public LoginDTO login(Integer id) {
        Employee employee = baseMapper.selectById(id);
        if (Objects.isNull(employee)) {
            return null;
        }

        HashMap<String, Object> claims = new HashMap<>();
        claims.put("employee_id", employee.getId());
        LoginDTO loginDTO = new LoginDTO();
        loginDTO.setToken(JwtUtil.createJWT("ezLogin",1000*24*60*60,claims));
        loginDTO.setName(employee.getName());
        return loginDTO;
    }
}
